<!--
	Copyright (C) 2010 Ethan Gruber
	EADitor: http://code.google.com/p/eaditor/
	Apache License 2.0: http://code.google.com/p/eaditor/
	
	Delete selected EAD guide from eXist (or other interface).  It will also delete from Solr.  This is linked from the file list page -->
<html xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xforms="http://www.w3.org/2002/xforms"
	xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:fr="http://orbeon.org/oxf/xml/form-runner" xmlns="http://www.w3.org/1999/xhtml"
	xmlns:xi="http://www.w3.org/2001/XInclude">
	<head>
		<title>EADitor: Delete</title>
		<link type="text/css" href="http://localhost:8080/cocoon/numishare/xforms.css"
			rel="stylesheet"/>
		<xforms:model>
			<xforms:instance id="id">
				<!-- Start with placeholders for three files -->
				<id xmlns=""/>
			</xforms:instance>
			
			<xforms:instance id="site-info">
				<site_info xmlns="">
					<title/>
					<pages>
						<page stub="" id="">
							<title/>
							<short-title/>
							<public/>
							<text/>
						</page>
					</pages>
				</site_info>
			</xforms:instance>

			<xforms:instance id="status">
				<status/>
			</xforms:instance>

			<!-- get title from url parameter -->
			<xforms:instance id="verification">
				<verification xmlns="">Are you sure you want to delete <title/> from the
					system?</verification>
			</xforms:instance>

			<!-- get id parameter and set that to be the file to delete -->
			<xforms:action ev:event="xforms-model-construct-done">
				<xforms:setvalue ref="instance('id')" value="xxforms:get-request-parameter('id')"/>
				<xforms:setvalue ref="instance('verification')/title"
					value="xxforms:get-request-parameter('title')"/>
				<xforms:send submission="load-submission"/>
			</xforms:action>
			
			<xforms:submission id="load-submission" serialization="none" method="get"
				action="/exist/rest/db/numishare/site_info.xml" xxforms:username="admin"
				xxforms:password="admin" replace="instance" instance="site-info"/>

			<xforms:submission id="save-submission" ref="instance('site-info')"
				xxforms:username="admin" xxforms:password="admin"
				action="/exist/rest/db/numishare/site_info.xml" method="put" replace="none">
				<xforms:setvalue ev:event="xforms-submit-done" ref="instance('status')">Page deleted.</xforms:setvalue>
				<xforms:toggle case="deleted" ev:event="xforms-submit-done"/>
				<xforms:message ev:event="xforms-submit-error" level="modal">Error deleting page!</xforms:message>
			</xforms:submission>
		</xforms:model>
	</head>
	<body>
		<xforms:switch>
			<xforms:case id="question">
				<p><xforms:output ref="instance('verification')"/></p>

				<xforms:trigger appearance="full">
					<xforms:label class="file_control">OK</xforms:label>
					<xforms:action ev:event="DOMActivate">
						<xforms:delete nodeset="instance('site-info')//page[@id=instance('id')]"/>
						<xforms:send submission="save-submission"/>
					</xforms:action>
				</xforms:trigger>
			</xforms:case>
			<xforms:case id="deleted">
				<xforms:group ref="instance('status')/text()">
					<div class="success">
						<xforms:output ref="instance('status')"/>
					</div>
				</xforms:group>
			</xforms:case>
		</xforms:switch>
	</body>
</html>
